package com.zhisheng.core.web.action;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.zhisheng.core.page.Page;
import com.zhisheng.core.security.entity.User;
import com.zhisheng.core.security.support.SecurityUserHolder;


/**   
 * @author wuhj
 * @since 2008-4-24
 * @version $Id$
 */
public class BaseAction extends ActionSupport implements RequestAware,SessionAware {

	private static final long serialVersionUID = 2577519329384713132L;

	private Map errorStack;
	
	private String infoMessage;
	
	private String errorMessage;
	
	protected Map session;
	
	protected Map request;
	
	private Page page; 
	/**
	 * @return the infoMessage
	 */
	public String getInfoMessage() {
		return infoMessage;
	}
	
	public String getInfoMessageText() {
		if(StringUtils.isEmpty(infoMessage)){
			return infoMessage;
		}
		return this.getText(infoMessage);
	}
	
	/**
	 * @param infoMessage the infoMessage to set
	 */
	public void setInfoMessage(String infoMessage) {
		this.infoMessage = infoMessage;
	}
	
	/**
	 * @return the errorMessage
	 */
	public String getErrorMessage() {
		return errorMessage;
	}
	
	
	public String getErrorMessageText() {
		if(StringUtils.isEmpty(errorMessage)){
			return errorMessage;
		}
		return this.getText(errorMessage);
	}
	
	/**
	 * @param errorMessage the errorMessage to set
	 */
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	
	/**
	 * @return the errorStack
	 */
	public Map getErrorStack() {
		return errorStack;
	}

	/**
	 * @param errorStack
	 *            the errorStack to set
	 */
	public void setErrorStack(Map errorStack) {
		this.errorStack = errorStack;
	}

	/*---------------------------common method end---------------------------------------------------*/

	/* (non-Javadoc)
	 * @see org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
	 */
	public void setSession(Map sessionMap) {
		this.session = sessionMap;
	}

	/**
	 * Returns the currentUser
	 * 
	 * @return
	 */
    public User getCurrentUser() {
    	return SecurityUserHolder.getCurrentUser();
    }

	public void setRequest(Map requestMap) {
		this.request=requestMap;
	}
	
	public Page createPage(){
		if(page == null){
			page = new Page();	
			page.setCurrentPage(1);
		}
        return page;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}
	
}
